package com.tb.ClassSchedule;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by guich on 2016/8/16.
 */
public class LessonViewForDay extends LinearLayout implements View.OnClickListener{

    private Lesson lesson;
    private boolean isVoid;
    private int color;

    public LessonViewForDay(Context context,Lesson lesson, boolean notTime) {
        super(context);

        this.lesson = lesson;

        LayoutInflater.from(context).inflate(R.layout.class_view_day,this);

        TextView section = (TextView) findViewById(R.id.section);
        TextView name = (TextView) findViewById(R.id.class_name);
        TextView address = (TextView) findViewById(R.id.class_address);


        section.setText(lesson.getStartSection() + " - " + lesson.getEndSection());
        name.setText(lesson.getName());
//        address.setText(lesson.getBuilding() + lesson.getClassNumber());
        address.setText(lesson.getAddress());

        LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.setMargins(5,5,5,5);
        setLayoutParams(params);

        if(lesson.getName().equals("—") || lesson.getName().equals(" ") || lesson.getName().equals("占位")){
            isVoid = true;
        }

        if(isVoid){
            setVisibility(GONE);
        }else if (notTime){
            section.setTextColor(Color.WHITE);
            name.setTextColor(Color.WHITE);
            address.setTextColor(Color.WHITE);
            setBackgroundColor(Color.GRAY);
        }else{
            int r = (int)(Math.random() * 130) + 125;
            int g = (int)(Math.random() * 130) + 125;
            int b = (int)(Math.random() * 130) + 125;
            color = Color.rgb(r,g,b);
            setBackgroundColor(color);
        }

        if(!isVoid){
            setOnClickListener(this);
        }

    }


    @Override
    public void onClick(View view) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("LessonInfo",lesson);

        Intent intent = new Intent(MainActivity.main,LessonViewActivity.class);
        intent.putExtras(bundle);
        intent.putExtra("Color",color);
        MainActivity.main.startActivity(intent);
    }
}
